package com.animations;

import com.beans.BirdBean;
import creator.ui.graphics.Magicanvas;
import creator.ui.graphics.bean.Switch;
import creator.ui.graphics.polaroid.Animation;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class BirdRotateAction extends Animation {

  private static boolean isDown = false;

  public void loadBean() {}

  public void paint(Graphics g) {}

  public synchronized void run() {
    LoadMouseListener(getMagicanvas());
    doRotate();
  }

  private void doRotate() {
    while (Switch._isContinue()) try {
      if (!BirdBean._isAlive()) {
        int i1 = BirdBean.getR();
        while (i1 <= 90) {
          if (i1 > 90) {
            i1 = 90;
            break;
          }
          i1++;
          BirdBean.setR(i1);
          Thread.sleep(3L);
          getMagicanvas().repaint();
        }
        break;
      }
      Thread.sleep(200L);
    } catch (InterruptedException e1) {
      e1.printStackTrace();
    }
  }

  private void LoadMouseListener(Magicanvas magicanvas) {
    magicanvas.addMouseListener(
      new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
          BirdRotateAction.isDown = true;
        }

        public void mouseReleased(MouseEvent e) {
          BirdRotateAction.isDown = false;
          if (
            (Tag._isPlay()) && (Tag._isDisappear()) && (BirdBean._isAlive())
          ) BirdRotateAction.access$1(BirdRotateAction.this.getMagicanvas());
        }
      }
    );
    magicanvas.addKeyListener(
      new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
          BirdRotateAction.isDown = true;
        }

        public void keyReleased(KeyEvent e) {
          BirdRotateAction.isDown = false;
          if (
            (Tag._isPlay()) && (Tag._isDisappear()) && (BirdBean._isAlive())
          ) BirdRotateAction.access$1(BirdRotateAction.this.getMagicanvas());
        }
      }
    );
  }

  private static void Rotate(Magicanvas mgicav) {
    new Thread(
      new Runnable(mgicav) {
        public void run() {
          try {
            spinOn();
            Thread.sleep(320L);
            spinUnderBit();
            spinUnderFinal();
          } catch (InterruptedException e1) {
            e1.printStackTrace();
          }
        }

        private void spinOn() {
          int i = BirdBean.getR();
          while (true) {
            if (i <= -15) {
              i = -15;
              break;
            }
            i -= 5;
            BirdBean.setR(i);
            try {
              Thread.sleep(4L);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
            BirdRotateAction.this.repaint();
          }
        }

        private void spinUnderBit() {
          int i1 = BirdBean.getR();
          while ((i1 <= 40) && (!BirdRotateAction.isDown)) {
            if (i1 > 40) {
              i1 = 40;
              break;
            }
            i1++;
            BirdBean.setR(i1);
            try {
              Thread.sleep(6L);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
            BirdRotateAction.this.repaint();
          }
        }

        private void spinUnderFinal() {
          int i1 = BirdBean.getR();
          while ((i1 <= 90) && (!BirdRotateAction.isDown)) {
            if (i1 > 90) {
              i1 = 90;
              break;
            }
            i1++;
            BirdBean.setR(i1);
            try {
              Thread.sleep(3L);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
            BirdRotateAction.this.repaint();
          }
        }
      }
    )
      .start();
  }
}
